/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.media;

import java.awt.Dimension;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

/**
 * Shows an Image
 * 
 * @author Pascal
 */
public class PictureWindow extends javax.swing.JFrame {

    /**
     * Creates new form PictureWindow
     */
    public PictureWindow(String title, Image image) {
        if (title == null || image == null)
            throw new NullPointerException();
        
        initComponents();
        setTitle(title);
        
        int width = image.getWidth(null);
        int height = image.getHeight(null);
        
        Dimension screenSize = getToolkit().getScreenSize();
        
        //check if pic is fully loaded and getWidth and getHeight calls were successful
        if (width != -1 && height != -1) {
            if (screenSize.getWidth() > width || screenSize.getHeight() > height) {
                //if screen is smaller than pic, set size of frame to size of pic
                setSize(new Dimension(width, height));
            }
            else {
                //maximize the frame
                setExtendedState(JFrame.MAXIMIZED_BOTH);
            }
        }
        
        picLabel.setIcon(new ImageIcon(image));
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        picLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(500, 400));
        getContentPane().setLayout(new java.awt.CardLayout());

        jScrollPane1.setViewportView(picLabel);

        getContentPane().add(jScrollPane1, "card3");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel picLabel;
    // End of variables declaration//GEN-END:variables
}
